﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using InstantNaukriDAL;
public partial class EditPersonalInfo : System.Web.UI.Page
{
    int ProfileId = 0, UserId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["UserId"] == null)
                Response.Redirect("Default.aspx");
            string roleid = "";
            clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
            if (Request.QueryString["roleid"] != null)
                roleid = clsEncryptionDecryption.Decrypt(Request.QueryString["roleid"].ToString());
            if (roleid == "4")
            {
                IN_TB_USER objIN_TB_USER = new IN_TB_USER();
                if (Session["UserId"] != null)
                    objIN_TB_USER = objclsUserLoginDAL.GetUserByID(Convert.ToInt32(Session["UserId"].ToString()));
                if (objIN_TB_USER != null)
                {
                    Session["UserId"] = objIN_TB_USER.ID;
                    dvAutority.Visible = true;
                    FillPersonalInfo(objIN_TB_USER.ID);
                }
            }
        }
    }
    protected void btnupdateGeneralInfo_Click(object sender, EventArgs e)
    {
         try
        {


            clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
            //Saving User
            IN_TB_USER objIN_TB_USER = new IN_TB_USER();

            if (ViewState["ProfileId"] != null)
            {
                clsProfileDAL objclsProfileDAL = new clsProfileDAL();
                IN_TB_PROFILE objIN_TB_PROFILE = new IN_TB_PROFILE();
                int pid = Convert.ToInt32(ViewState["ProfileId"].ToString());
                objIN_TB_PROFILE = objclsProfileDAL.GetProfileById(pid);
                objIN_TB_PROFILE.FATHER = txtFather.Text;
                objIN_TB_PROFILE.DOB = Convert.ToDateTime(txtDOB.Text);
                objIN_TB_PROFILE.GENDER = ddlGender.SelectedValue;
                objIN_TB_PROFILE.ALTERNATEEMAIL = txtAltEmail.Text;
                objIN_TB_PROFILE.PINCODE = txtPIN.Text;
                objIN_TB_PROFILE.MARITAL_STATUS = Convert.ToInt32(txtMaritalStatus.Text);
                objIN_TB_PROFILE.MAILING_ADDRESS = txtAddress.Text;

                if (Session["UserId"] != null)
                    objIN_TB_PROFILE.USER_ID = Convert.ToInt32(Session["UserId"]);
                int profieleid = objclsProfileDAL.SaveProfile(objIN_TB_PROFILE);
            }

            if (Request.QueryString["roleid"] != null && Session["UserId"] != null)
            {
                Response.Redirect("JobseekerPrieview.aspx?roleid=" + Request.QueryString["roleid"].ToString());
            }
            else
            {
                Session["RoleId"] = null;
                Response.Redirect("JobSeekerLogin.aspx");
            }
        }
        catch (Exception)
        {

            throw;
        }
    }
    protected void FillPersonalInfo(int UserId)
    {
        try
        {
            clsProfileDAL objclsProfileDAL = new clsProfileDAL();
            IN_TB_PROFILE objIN_TB_PROFILE = new IN_TB_PROFILE();
            objIN_TB_PROFILE = objclsProfileDAL.GetProfileByUserId(UserId);
            if (objIN_TB_PROFILE != null)
            {
                ViewState["ProfileId"] = objIN_TB_PROFILE.ID;
                DateTime dtdob = (DateTime)objIN_TB_PROFILE.DOB;
                txtDOB.Text = dtdob.ToString("dd-MMM-yyyy");
                ddlGender.SelectedValue = objIN_TB_PROFILE.GENDER;
                txtFather.Text = objIN_TB_PROFILE.FATHER;
                txtMaritalStatus.Text = Convert.ToInt32(objIN_TB_PROFILE.MARITAL_STATUS).ToString();
                txtAddress.Text = objIN_TB_PROFILE.MAILING_ADDRESS;
                txtPIN.Text = objIN_TB_PROFILE.PINCODE;
                txtAltEmail.Text = objIN_TB_PROFILE.ALTERNATEEMAIL;

            }
        }
        catch (Exception)
        {

            throw;
        }
    }

}
